﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GwLib.JqGridMvc;

namespace GwLib.SampleJqGrid.Models
{
    public class SampleModel
    {
        private static JqGrid _grid;

        public JqGridActionUrls ActionUrls { get; set; }

        public static JqGrid Grid
        {
            get
            {
                if (_grid == null)
                {
                    JqGridColumn col;
                    _grid = new JqGrid
                    {
                        Caption = "People In the List",
                        JQuerySelector = "#sampleGrid",
                        LoadCompleteFunction = "sampleGridHelper.loadComplete",
                        LoadErrorFunction = "sampleGridHelper.loadError",
                        ViewableRowCount = 500,
                        IsInitialWidthAutomatic = true,
                        DefaultSortColumnName = "FirstName",
                        DefaultSortAscending = true,
                        HeightType = JqGridHeightType.Custom,
                        CustomHeightTypeExpression = "sampleGridHelper.getEstimatedGridHeight()",
                        DoubleClickRowFunction = "sampleGridHelper.doubleClickRow"
                    };
                    _grid.Paging.Enabled = true;
                    _grid.Paging.RecordsPerPageCountOptions = new int[] { 20, 40, 60, 100, 500 };
                    _grid.Paging.ViewRecordCountInfo = true;
                    _grid.Paging.JQuerySelector = "#samplePager";
                    _grid.DataSource.DataType = JqGridDataType.Json;

                    col = new JqGridColumn { HeaderCaption = "First Name", Width = 100 };
                    col.MapTo<Person>(p => p.FirstName);
                    _grid.Columns.Add(col);

                    col = new JqGridColumn { HeaderCaption = "Last Name", Width = 100 };
                    col.MapTo<Person>(p => p.LastName);
                    _grid.Columns.Add(col);

                    col = new JqGridColumn { HeaderCaption = "Birth Date", Width = 100 };
                    col.MapTo<Person>(p => p.BirthDate);
                    _grid.Columns.Add(col);
                }
                return _grid;
            }
        }
    }
}